package com.retailcloud.baseservice.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.retailcloud.baseservice.vo.TenantsVo;
import com.retailcloud.commonutils.annotation.SysLog;
import com.retailcloud.commonutils.utils.PageUtils;
import com.retailcloud.commonutils.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.retailcloud.baseservice.entity.TenantsEntity;
import com.retailcloud.baseservice.service.TenantsService;

import javax.servlet.http.HttpServletRequest;


/**
 * 租户表
 *
 * @author wudi
 * @email 632132852@qq.com
 * @date 2024-11-02 19:41:19
 */
@RestController
@RequestMapping("/tenants")
public class TenantsController {
    @Autowired
    private TenantsService tenantsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions(":tenants:list")
    public R list(@RequestParam Map<String, Object> params, HttpServletRequest request) {
        PageUtils page = tenantsService.queryPage(params);
        //String authorization = request.getHeader("X-User-Name");
        //System.out.println(authorization);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tenantId}")
    //@RequiresPermissions(":tenants:info")
    public R info(@PathVariable("tenantId") String tenantId) {
        TenantsEntity tenants = tenantsService.getById(tenantId);

        return R.ok().put("data", tenants);
    }

    /**
     * 保存
     */
    @SysLog("新增企业信息和绑定用户企业信息")
    @RequestMapping("/save")
    //@RequiresPermissions(":tenants:save")
    public R save(@RequestBody TenantsVo tenants, HttpServletRequest request) {

        tenantsService.saveTenants(tenants, request);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions(":tenants:update")
    public R update(@RequestBody TenantsEntity tenants) {
        tenantsService.updateById(tenants);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions(":tenants:delete")
    public R delete(@RequestBody String[] tenantIds) {
        tenantsService.removeByIds(Arrays.asList(tenantIds));

        return R.ok();
    }

}
